import wx



class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        super().__init__(parent, title=title, size=(800, 600))
        # 创建一个面板
        panel = wx.Panel(self)
        # 创建一个垂直盒子布局管理器
        vbox = wx.BoxSizer(wx.VERTICAL)
        # 将盒子布局管理器设置为面板的布局管理器
        panel.SetSizer(vbox)

        self.data = {
            "name": "张三",
            "age": 18,
            "sex": "男",
            "birth": "1990-01-01",
            "address": "北京市",
            "phone": "13800138000",
            "list_box_selects1": ["选项1", "选项2", "选项3"],
            "list_box_selects2": ["选项1", "选项2", "选项3"],
            "list_box_selects3": ["选项1", "选项2", "选项3"],
            "mux_selectids":[]
        }



        # 菜单
        self.init_ui_menu()

        # 单行文本输入
        self.text_ctrl = wx.TextCtrl(panel, style=wx.TE_PROCESS_ENTER)
        vbox.Add(self.text_ctrl, 0, wx.ALL | wx.EXPAND, 5)

        # 多行文本输入
        self.text_ctrl2 = wx.TextCtrl(panel, style=wx.TE_MULTILINE)
        vbox.Add(self.text_ctrl2, 1, wx.ALL | wx.EXPAND, 5)

        # self.scroll_bar = wx.ScrolledWindow(panel)
        # vbox.Add(self.scroll_bar, 1, wx.ALL | wx.EXPAND, 5)

        # 密码输入
        self.text_ctrl3 = wx.TextCtrl(panel, style=wx.TE_PASSWORD)
        vbox.Add(self.text_ctrl3, 0, wx.ALL | wx.EXPAND, 5)

        # 按钮
        self.button = wx.Button(panel, label="点击我")
        vbox.Add(self.button, 0, wx.ALL | wx.CENTER, 5)

        # 有两组单选按钮，只要放在不同的容器，例如panel中，就可以做到相互不干扰
        birth_panel = self.init_ui_birth(panel)
        vbox.Add(birth_panel, 0, wx.ALL | wx.CENTER, 5)
        sex_panel = self.init_ui_sex(father_panel=panel)
        vbox.Add(sex_panel, 0, wx.ALL | wx.CENTER, 5)

        # 有两组多选按钮，只要放在不同的容器，例如panel中，就可以做到相互不干扰
        lan_panel = self.init_ui_languages(panel)
        vbox.Add(lan_panel, 0, wx.ALL | wx.CENTER, 5)

        sports_panel = self.init_ui_sports(panel)
        vbox.Add(sports_panel, 0, wx.ALL | wx.CENTER, 5)

        # 单选框
        self.radio_box = wx.RadioBox(panel, label="单选框", choices=["选项1", "选项2", "选项3"])
        vbox.Add(self.radio_box, 0, wx.ALL | wx.CENTER, 5)

        # 下拉框
        self.combo_box = wx.ComboBox(panel, choices=["选项1", "选项2", "选项3"])
        vbox.Add(self.combo_box, 0, wx.ALL | wx.LEFT, 5)


        single_list_box_panel = self.init_ui_single_list_box(panel)
        vbox.Add(single_list_box_panel, 0, wx.ALL | wx.LEFT | wx.EXPAND, 5)

        mux_list_box_panel = self.init_ui_mux_list_box(panel)
        vbox.Add(mux_list_box_panel, 0, wx.ALL | wx.LEFT | wx.EXPAND, 5)

        # 滑块
        self.slider = wx.Slider(panel, value=50, minValue=0, maxValue=100)
        vbox.Add(self.slider, 0, wx.ALL | wx.CENTER, 5)

        # 进度条
        self.progress_bar = wx.Gauge(panel, range=100)
        vbox.Add(self.progress_bar, 0, wx.ALL | wx.CENTER, 5)

        # 静态文本
        self.static_text = wx.StaticText(panel, label="静态文本")
        vbox.Add(self.static_text, 0, wx.ALL | wx.CENTER, 5)

        # 位图
        # self.bitmap = wx.StaticBitmap(panel, bitmap=wx.Bitmap("./images/taiyang1.png"))
        # vbox.Add(self.bitmap, 0, wx.ALL | wx.CENTER, 5)
        # 富文本
        # self.rich_text = wx.RichTextCtrl(panel)
        # vbox.Add(self.rich_text, 1, wx.ALL | wx.EXPAND, 5)
        # 滚动条



        # 状态栏
        self.status_bar = self.CreateStatusBar()
        self.status_bar.SetStatusText("状态栏")

        # # 创建一个打开模态对话框的按钮
        # self.button = wx.Button(panel, label="打开对话框")
        # vbox.Add(self.button, 0, wx.ALL | wx.CENTER, 5)
        # self.button.Bind(wx.EVT_BUTTON, self.on_button_click)
        #
        # # 创建一个打开非模态对话框的按钮
        # self.button2 = wx.Button(panel, label="打开非模态对话框")
        # vbox.Add(self.button2, 0, wx.ALL | wx.CENTER, 5)
        # self.button2.Bind(wx.EVT_BUTTON, self.on_button_click2)

    # 自定义窗口类
    def init_ui_single_list_box(self, panel: wx.Panel) -> wx.Panel:
        list_panel = wx.Panel(panel)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        # 创建静态文本
        label = wx.StaticText(list_panel, label="单选列表框")
        hbox.Add(label, 0, wx.ALL | wx.LEFT, 5)
        # # 列表框
        list_box = wx.ListBox(list_panel, choices=self.data['list_box_selects1'], style=wx.LB_SINGLE)
        hbox.Add(list_box, 1, wx.ALL | wx.EXPAND, 5)
        # 给列表框绑定选中事件
        list_box.Bind(wx.EVT_LISTBOX, self.on_list_box_select)

        list_panel.SetSizer(hbox)
        return list_panel

    def init_ui_mux_list_box(self, panel: wx.Panel) -> wx.Panel:
        list_panel = wx.Panel(panel)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        # 创建静态文本
        label = wx.StaticText(list_panel, label="多选列表框")
        hbox.Add(label, 0, wx.ALL | wx.LEFT, 5)

        # 列表框
        list_box = wx.ListBox(list_panel, choices=self.data['list_box_selects2'], style=wx.LB_MULTIPLE)
        hbox.Add(list_box, 1, wx.ALL | wx.EXPAND, 5)
        # 给列表框绑定选中事件
        list_box.Bind(wx.EVT_LISTBOX, self.on_list_box_select2)
        list_box.Bind(wx.EVT_LISTBOX_DCLICK, self.on_list_box_select2)

        list_panel.SetSizer(hbox)
        return list_panel

    def on_list_box_select(self, event:wx.CommandEvent)->None:
        # 获取选中的项
        selection = event.GetSelection()
        if selection == -1:
            return
        else:
            # 获取选中的项的标签
            label = self.data['list_box_selects1'][selection]
            # 打印选中的项的标签
            print(label)

    def on_list_box_select2(self, event):

        # 获取选中的项
        selection = event.GetSelection()
        if selection == -1:
            return
        else:
            # 获取选中的项的标签
            label = self.data['list_box_selects2'][selection]
            # 打印选中的项的标签
            print(label)

    def init_ui_menu(self):
        menu_bar = wx.MenuBar()
        self.SetMenuBar(menu_bar)

        file_menu = wx.Menu()
        file_menu.Append(wx.ID_NEW, "新建")
        file_menu.Append(wx.ID_EXIT, "退出")
        file_menu.Append(wx.ID_ABOUT, "关于")
        file_menu.Append(wx.ID_HELP, "帮助")
        file_menu.Append(wx.ID_PREFERENCES, "设置")
        file_menu.Append(wx.ID_PRINT, "打印")
        file_menu.Append(wx.ID_SAVE, "保存")
        file_menu.Append(wx.ID_OPEN, "打开")
        menu_bar.Append(file_menu, "文件")

        edit_menu = wx.Menu()
        edit_menu.Append(wx.ID_COPY, "复制")
        edit_menu.Append(wx.ID_PASTE, "粘贴")
        edit_menu.Append(wx.ID_CUT, "剪切")
        edit_menu.Append(wx.ID_UNDO, "撤销")
        edit_menu.Append(wx.ID_REDO, "重做")
        menu_bar.Append(edit_menu, "编辑")

        view_menu = wx.Menu()
        view_menu.Append(wx.ID_ZOOM_IN, "放大")
        view_menu.Append(wx.ID_ZOOM_OUT, "缩小")
        view_menu.Append(wx.ID_ZOOM_100, "100%")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应窗口")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应页面")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应选择")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应矩形")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应窗口")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应页面")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应选择")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应矩形")
        view_menu.Append(wx.ID_ZOOM_FIT, "适应窗口")
        menu_bar.Append(view_menu, "查看")

        help_menu = wx.Menu()
        help_menu.Append(wx.ID_HELP, "帮助")
        help_menu.Append(wx.ID_HELP_INDEX, "帮助索引")
        help_menu.Append(wx.ID_HELP_CONTENTS, "帮助内容")
        help_menu.Append(wx.ID_HELP_SEARCH, "帮助搜索")
        help_menu.Append(wx.ID_HELP_PROCEDURES, "关于")
        menu_bar.Append(help_menu, "帮助")

        # tool_bar = self.CreateToolBar()
        # tool_bar.AddTool(wx.ID_NEW, "新建")
        # tool_bar.AddTool(wx.ID_OPEN, "打开")
        # tool_bar.AddTool(wx.ID_SAVE, "保存")
        # tool_bar.AddTool(wx.ID_PRINT, "打印")
        # tool_bar.AddTool(wx.ID_EXIT, "退出")
        # tool_bar.Realize()

    def on_button_click(self, event):
        # 创建一个对话框
        self.dialog = wx.MessageDialog(self, "这是一个对话框", "对话框标题", wx.OK | wx.CANCEL)
        self.dialog.ShowModal()

    def on_button_click2(self, event):
        # 创建一个非模态对话框
        self.dialog = wx.MessageDialog(self, "这是一个对话框", "对话框标题", wx.OK | wx.CANCEL)
        self.dialog.ShowModal()

    def init_ui_sports(self, panel):
        sports_panel = wx.Panel(panel)
        # 喜欢的运动复选框组
        # 创建一个横向的布局box
        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        # 创建一个静态文本
        self.label2 = wx.StaticText(sports_panel, label="请选择您喜欢的运动：")
        hbox2.Add(self.label2, 0, wx.ALL | wx.CENTER, 5)
        # 复选框
        self.like_basketball = wx.CheckBox(sports_panel, label="喜欢篮球")
        hbox2.Add(self.like_basketball, 0, wx.ALL | wx.CENTER, 5)
        self.like_football = wx.CheckBox(sports_panel, label="喜欢足球")
        hbox2.Add(self.like_football, 0, wx.ALL | wx.CENTER, 5)
        self.like_volleyball = wx.CheckBox(sports_panel, label="喜欢排球")
        hbox2.Add(self.like_volleyball, 0, wx.ALL | wx.CENTER, 5)
        self.like_tennis = wx.CheckBox(sports_panel, label="喜欢网球")
        hbox2.Add(self.like_tennis, 0, wx.ALL | wx.CENTER, 5)
        self.like_swimming = wx.CheckBox(sports_panel, label="喜欢游泳")
        hbox2.Add(self.like_swimming, 0, wx.ALL | wx.CENTER, 5)
        self.like_running = wx.CheckBox(sports_panel, label="喜欢跑步")
        hbox2.Add(self.like_running, 0, wx.ALL | wx.CENTER, 5)
        sports_panel.SetSizer(hbox2)
        return sports_panel

    def init_ui_languages(self, panel):
        lan_panel = wx.Panel(panel)
        # 创建一个横向布局的box
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        # 创建一个静态文本
        self.label = wx.StaticText(lan_panel, label="请选择编程语言：")
        hbox.Add(self.label, 0, wx.ALL | wx.CENTER, 5)
        # 复选框
        self.checkbox = wx.CheckBox(lan_panel, label="java")
        # self.checkbox.SetValue(True)
        hbox.Add(self.checkbox, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox2 = wx.CheckBox(lan_panel, label="python")
        # self.checkbox2.SetValue(True)
        hbox.Add(self.checkbox2, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox3 = wx.CheckBox(lan_panel, label="c++")
        # self.checkbox3.SetValue(True)
        hbox.Add(self.checkbox3, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox4 = wx.CheckBox(lan_panel, label="c#")
        # self.checkbox4.SetValue(True)
        hbox.Add(self.checkbox4, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox5 = wx.CheckBox(lan_panel, label="php")
        # self.checkbox5.SetValue(True)
        hbox.Add(self.checkbox5, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox6 = wx.CheckBox(lan_panel, label="javascript")
        # self.checkbox6.SetValue(True)
        hbox.Add(self.checkbox6, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox7 = wx.CheckBox(lan_panel, label="ruby")
        # self.checkbox7.SetValue(True)
        hbox.Add(self.checkbox7, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox8 = wx.CheckBox(lan_panel, label="go")
        # self.checkbox8.SetValue(True)
        hbox.Add(self.checkbox8, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox9 = wx.CheckBox(lan_panel, label="rust")
        # self.checkbox9.SetValue(True)
        hbox.Add(self.checkbox9, 0, wx.ALL | wx.CENTER, 5)
        self.checkbox10 = wx.CheckBox(lan_panel, label="swift")
        # self.checkbox10.SetValue(True)
        hbox.Add(self.checkbox10, 0, wx.ALL | wx.CENTER, 5)
        lan_panel.SetSizer(hbox)
        return lan_panel

    def init_ui_birth(self, panel):
        # 创建一个新的面板用于出生地点的单选按钮
        birth_panel = wx.Panel(panel)
        birth_sizer = wx.BoxSizer(wx.HORIZONTAL)
        birth_panel.SetSizer(birth_sizer)
        # 创建一个静态文本
        self.label = wx.StaticText(birth_panel, label="出生地点：")
        birth_sizer.Add(self.label, 0, wx.ALL | wx.CENTER, 5)
        # 创建单选按钮
        self.radio_button = wx.RadioButton(birth_panel, label="广州")
        birth_sizer.Add(self.radio_button, 0, wx.ALL | wx.CENTER, 5)
        # 创建单选按钮
        self.radio_button2 = wx.RadioButton(birth_panel, label="深圳")
        birth_sizer.Add(self.radio_button2, 0, wx.ALL | wx.CENTER, 5)
        # 创建单选按钮
        self.radio_button3 = wx.RadioButton(birth_panel, label="北京")
        birth_sizer.Add(self.radio_button3, 0, wx.ALL | wx.CENTER, 5)
        return birth_panel

    def init_ui_sex(self, father_panel):
        # 创建一个性别panel
        sex_panel = wx.Panel(father_panel)
        # 创建一个横向的box
        sex_sizer = wx.BoxSizer(wx.HORIZONTAL)
        # 将box设置为panel的布局
        sex_panel.SetSizer(sex_sizer)

        # 创建一个静态文本
        self.label2 = wx.StaticText(sex_panel, label="性别：")
        sex_sizer.Add(self.label2, 0, wx.ALL | wx.CENTER, 5)

        # 创建单选按钮
        self.radio_button4 = wx.RadioButton(sex_panel, label="男")
        sex_sizer.Add(self.radio_button4, 0, wx.ALL | wx.CENTER, 5)
        # 创建单选按钮
        self.radio_button5 = wx.RadioButton(sex_panel, label="女")
        sex_sizer.Add(self.radio_button5, 0, wx.ALL | wx.CENTER, 5)
        return sex_panel







if __name__ == "__main__":
    # 创建一个应用程序
    app = wx.App()
    # 创建一个窗口
    frame = MyFrame(None, title="Hello, wxPython!")
    # 显示窗口
    frame.Show()
    # 运行应用程序
    app.MainLoop()
